<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数据类型转换</title>
</head>
<body>
    <div id="d1">123</div>
  <script type="text/javascript">
      /*
        显示类型转换
       */
      let str1 = "456"; // 此时是一个string类型
      let num1 = parseInt(str1);
      console.log(typeof num1 + ":" + num1);

      let num2 = 123;
      let str2 = num2.toString(); // 数字类型转字符串类型
      console.log(typeof str2 + ":" + str2);

      /*
       隐式类型转换
       */
      let a = 5;
      let b = "10";
      let c = a + b;
      console.log(typeof c + ":" + c);

      // 字符串和数字进行比较 把字符串转换为数字 然后进行比较
      console.log("666" == 666); // true

      // JavaScript 在进行逻辑运行的时候 会把非布尔类型转换为布尔类型
      console.log(!!100);

      let str3 = "abc";
      console.log(parseInt(str3)); // 结果NaN

      let str4 = "abc123"

      let a1 = parseInt(str3); // 结果是NaN
      let a2 = parseInt(str4); // 结果是NaN
      console.log(a1 == a2);

      console.log(isNaN(a1)); // true
      console.log(isNaN("hello")); // true
      console.log(isNaN(123)); // false
  </script>
</body>
</html>